<template>
  <div>
    <form ref="form" :action="formActionUrl" id="alipay" name="alipay" method="post"></form>
    <el-button type="primary" icon="el-icon-money" @click="pagePay">支付宝支付</el-button>
  </div>
</template>

<script>
import api from "../api";

export default {
  name: "alipayTest",
  data() {
    return {
      formActionUrl: '',
      price: '12', // 订单金额
    };
  },
  methods: {
    pagePay() {
      api.getAlipay(this.price).then(response => {
        this.$refs.form.action = response.data;  // 将form的action属性设置为后端返回的支付宝支付页面URL
        this.$refs.form.submit();  // 提交form
      }).catch(error => {
        console.error(error);
      });
    },
  },
}
</script>

<style scoped>

</style>